home *** CD-ROM | disk | FTP | other *** search
- /*
- ** File: Event.c
- **
- ** Written by: Bill Hayden
- ** Nikol Software
- **
- ** Copyright © 1995 Nikol Software
- ** All rights reserved.
- */
-
-
-
- #include "MacWT.h"
- #include "Constants.h"
- #include "Menu.h"
- #include "Event.h"
- #include "input.h"
- #include "graphics.h"
- #include <math.h>
- #include "StringUtils.h"
- #include "ShowHideMenubar.h"
-
-
-
- static void ProcessGameEvent(void);
-
- static void add_special(Intent *intent, int special);
-
-
- static Boolean gInBackground = false;
- Intent gIntent;
-
-
-
- /*****************************************************************************/
-
-
-
-
- void EventLoop(void)
- {
- while (!quitting)
- {
- if (gGameOn && !gPaused)
- {
- UpdateGameScreen();
- ProcessGameEvent();
- }
- else
- ProcessEvent();
- }
- }
-
-
-
-
- /*****************************************************************************/
-
-
-
-
- Boolean ProcessEvent(void)
- {
- WindowRef whichWindow;
- long menuResult;
- short partCode;
- char ch;
-
-
- if (!WaitNextEvent(everyEvent, &gTheEvent, gInBackground ? kBackTime : kFrontTime, nil))
- return FALSE;
-
- switch (gTheEvent.what)
- {
- case mouseDown:
-
- switch (partCode = FindWindow(gTheEvent.where, &whichWindow)) {
-
- case inSysWindow:
- SystemClick(&gTheEvent, (WindowPtr)whichWindow);
- break;
-
- case inMenuBar:
- DoAdjustMenus();
- DoMenuCommand(MenuSelect(gTheEvent.where));
- break;
-
- case inDrag:
- SelectWindow(whichWindow);
- DragWindow(whichWindow, gTheEvent.where, &qd.screenBits.bounds);
- break;
-
- case inContent:
- if (whichWindow != FrontWindow())
- SelectWindow(whichWindow);
- break;
-
- case inGoAway:
- if (TrackGoAway(whichWindow, gTheEvent.where))
- ExitToShell();
- break;
-
- default:
- break;
-
- } // switch (FindWindow)
- break;
-
-
- case keyDown:
- ObscureCursor();
- // FALL THRU
-
- case autoKey:
- ch = gTheEvent.message; // automagic "& charCodeMask" :)
- if (gTheEvent.modifiers & cmdKey)
- {
- DoAdjustMenus();
- menuResult = MenuKey(ch);
- if (menuResult & 0xFFFF0000)
- {
- DoMenuCommand(menuResult);
- break; // out of this switch if it was a menu command
- }
- }
-
- switch (ch)
- {
- case kTab:
- TogglePause();
- break;
-
- case '8':
- //case kUpArrow:
- BeginGame();
- break;
- }
- break;
-
-
- case updateEvt:
- {
- GrafPtr savePort;
-
- whichWindow = (WindowRef)gTheEvent.message;
-
- GetPort(&savePort);
- SetPortWindowPort(whichWindow);
-
- BeginUpdate(whichWindow);
-
- if (whichWindow == (WindowRef)gWindow)
- {
- UpdateDialog(gWindow, gWindow->visRgn);
- DrawGameScreen();
- if (gPaused)
- ShowPausedScreen();
- else if (!gGameOn)
- MacAttractMode();
- }
-
- EndUpdate(whichWindow);
-
- SetPort(savePort);
- }
- break;
-
- case diskEvt:
- case activateEvt:
- break;
-
- case osEvt:
- if ((gTheEvent.message << 31) == 0) // suspend event
- {
- if (!gPaused)
- TogglePause();
- gInBackground = true;
- }
- else
- {
- gInBackground = false;
- SetPortWindowPort(GetDialogWindow(gWindow));
- }
- break;
-
- case kHighLevelEvent:
- AEProcessAppleEvent(&gTheEvent);
- break;
-
- default:
- break;
- }
-
- return TRUE;
- }
-
-
- /*****************************************************************************/
-
-
-
- static void ProcessGameEvent(void)
- {
- KeyMap kmap;
- unsigned char *kmp = (unsigned char *)&kmap;
- Boolean rotating_cw,
- rotating_ccw,
- moving_forward,
- moving_backward,
- running,
- strafing;
- struct {
- short rightArrow,
- leftArrow,
- upArrow,
- downArrow,
- control,
- escape,
- shift,
- space,
- tab,
- w,
- e,
- r,
- t,
- y,
- plus,
- minus;
- } keyboard;
-
-
- gIntent.force_x = gIntent.force_y = gIntent.force_z = 0.0;
- gIntent.force_rotate = 0.0;
- gIntent.n_special = 0;
-
- GetKeys(kmap);
-
- keyboard.rightArrow = MacKeyDown(kmp, 0x7C) || MacKeyDown(kmp, 0x58);
- keyboard.leftArrow = MacKeyDown(kmp, 0x7b) || MacKeyDown(kmp, 0x56);
- keyboard.upArrow = MacKeyDown(kmp, 0x7e) || MacKeyDown(kmp, 0x5b);
- keyboard.downArrow = MacKeyDown(kmp, 0x7d) || MacKeyDown(kmp, 0x54);
- keyboard.control = MacKeyDown(kmp, 0x3b) || M